module executor.user.UserLeaveExecutor;


import msgtrans;
import message.Constants;
import message.MsgDefine;
import google.protobuf;
import hunt.logging;
import std.array;
import hunt.util.Serialize;
import client.MsgServerClient;
import client.LogicServerClient;
import cache.UserStatusManager;

@TransportServer(MsgServerName)
class UserLeaveExecutor : AbstractExecutor!(UserLeaveExecutor) {

  @MessageId(MESSAGE.CMD_OFFLINE)
  void clientLeave(TransportContext ctx, MessageBuffer buffer) {
    UserStatus userStatus = new UserStatus;
    buffer.data.fromProtobuf!UserStatus(userStatus);
    //string userId = cast(string)buffer.data;
    logInfo("CMD_OFFLINE %s",userStatus.userId);
    UserStatusManager.getInstance().setUserStatus(userStatus.userId,userStatus.src,false);
    if (!UserStatusManager.getInstance().getUserStatus(userStatus.userId))
    {
      MessageTransportClient logicClient =  LogicServerClient.getInstance().getForwardClient();
      logicClient.send(new MessageBuffer(MESSAGE.CMD_OFFLINE,cast(ubyte[])userStatus.userId));

    }
  }
}

